package com.msstudio;

// Decompiled by Jad v1.5.7g. Copyright 2000 Pavel Kouznetsov.
// Jad home page: http://www.geocities.com/SiliconValley/Bridge/8617/jad.html
// Decompiler options: packimports(3) fieldsfirst ansi 

import com.msstudio.utils.PkgTools;
import com.msstudio.utils.HttpPosterListener;
import com.msstudio.midlets.MSCMIDlet;
import java.util.Vector;
import javax.microedition.lcdui.*;

public class Finger
    implements CommandListener, HttpPosterListener
{

    protected Command cmdOk;
    protected Command cmdPre;
    protected Command cmdNext;
    protected Command cmdBack;
    protected Command cmdCancel;
    private Vector vFriend;
    private Vector vBack;
    int curUser;
    int num;
    private final int C_List_Area = 0;
    private final int C_List_Age = 1;
    private final int C_List_Sex = 2;
    private int curMenu;
    private Form form;
    private List theList;
    private Form getinforForm;
    private Displayable preWindow;
    private String iUIN;
    protected Command cmdBackGetInfor;
    private static final String listAge[] = {
        "< 16", "16 - 22", "22 - 30", "30 - 40", "> 40"
    };
    private static String listSex[] = new String[2];
    String strAge;
    String strSex;
    String strArea;

    public void doGetInfor(String s, Displayable displayable)
    {
        if(displayable != null)
        {
            iUIN = s;
            preWindow = displayable;
        }
        MSCMIDlet.httpPoster.getInfor(s, this);
    }

    public void cancelPre(Displayable displayable)
    {
        if(preWindow == displayable)
            preWindow = MSCMIDlet.mainForm.GetWindow();
    }

    public Finger()
    {
        cmdOk = null;
        cmdPre = null;
        cmdNext = null;
        cmdBack = null;
        cmdCancel = null;
        vFriend = new Vector();
        vBack = new Vector();
        form = null;
        theList = null;
        getinforForm = null;
        preWindow = null;
        iUIN = null;
        strAge = null;
        strSex = null;
        strArea = null;
    }

    public void show()
    {
        MSCMIDlet.multiLang.setProvinces();
        listSex[0] = MSCMIDlet.multiLang.sMale;
        listSex[1] = MSCMIDlet.multiLang.sFemale;
        cmdBack = new Command(MSCMIDlet.multiLang.sBack, 2, 3);
        showList(0);
    }

    private void showList(int i)
    {
        curMenu = i;
        switch(i)
        {
        case 0: // '\0'
            theList = new List(MSCMIDlet.multiLang.sSelectProvince, 3, MSCMIDlet.multiLang.listArea, null);
            break;

        case 1: // '\001'
            theList = new List(MSCMIDlet.multiLang.sSelectAge, 3, listAge, null);
            break;

        case 2: // '\002'
            theList = new List(MSCMIDlet.multiLang.sSelectSex, 3, listSex, null);
            break;
        }
        theList.addCommand(cmdBack);
        theList.setCommandListener(this);
        MSCMIDlet.display.setCurrent(theList);
    }

    private void GotoUser(int i)
    {
        curUser = i;
        if(i >= vFriend.size())
        {
            return;
        } else
        {
            int j = i * 5;
            form = new Form(MSCMIDlet.multiLang.sResearchResult);
            form.addCommand(cmdOk);
            form.addCommand(cmdPre);
            form.addCommand(cmdNext);
            form.addCommand(cmdCancel);
            form.setCommandListener(this);
            String s = MSCMIDlet.multiLang.GetCombineMsg(28, (String)vFriend.elementAt(j), (String)vFriend.elementAt(j + 1), (String)vFriend.elementAt(j + 2), (String)vFriend.elementAt(j + 3), (String)vFriend.elementAt(j + 4));
            form.append(s);
            return;
        }
    }

    public void commandAction(Command command, Displayable displayable)
    {
        if(command == List.SELECT_COMMAND)
        {
            switch(curMenu)
            {
            case 0: // '\0'
                strArea = Long.toString((theList.getSelectedIndex() + 2) % 34);
                showList(1);
                break;

            case 1: // '\001'
                strAge = Long.toString(theList.getSelectedIndex());
                showList(2);
                break;

            case 2: // '\002'
                strSex = Long.toString(theList.getSelectedIndex());
                MSCMIDlet.mainForm.show();
                MSCMIDlet.httpPoster.finger(strAge, strSex, strArea, this);
                break;
            }
            return;
        }
        if(command == cmdOk)
            MSCMIDlet.addFriend.show(form, (String)vFriend.elementAt(5 * curUser + 1));
        if(command == cmdPre)
        {
            synchronized(this)
            {
                curUser--;
                if(curUser < 0)
                    curUser = num - 1;
                GotoUser(curUser);
            }
            MSCMIDlet.display.setCurrent(form);
        }
        if(command == cmdNext)
        {
            synchronized(this)
            {
                curUser++;
                if(curUser >= num)
                    curUser = 0;
                GotoUser(curUser);
            }
            MSCMIDlet.display.setCurrent(form);
        }
        if(command == cmdBack)
        {
            switch(curMenu)
            {
            case 0: // '\0'
                MSCMIDlet.mainMenu.show();
                break;

            case 1: // '\001'
                showList(0);
                break;

            case 2: // '\002'
                showList(1);
                break;
            }
            return;
        }
        if(command == cmdCancel)
        {
            MSCMIDlet.mainForm.show();
            synchronized(this)
            {
                if(vBack.size() > 0)
                    vBack.removeElementAt(0);
                if(vBack.size() > 0)
                {
                    String s = (String)vBack.elementAt(0);
                    doNextResult(s);
                }
            }
            return;
        }
        try
        {
            if(command == cmdBackGetInfor)
            {
                form = null;
                MSCMIDlet.display.setCurrent(preWindow);
                return;
            }
        }
        catch(Exception exception) { }
        return;
    }

    public void doNextResult(String s)
    {
        String s1 = PkgTools.GetParaVal("SN", s);
        String s2 = PkgTools.GetParaVal("UN", s);
        String s3 = PkgTools.GetParaVal("NK", s);
        String s4 = PkgTools.GetParaVal("AG", s);
        String s5 = PkgTools.GetParaVal("SX", s);
        String s6 = PkgTools.GetParaVal("PV", s);
        try
        {
            num = Integer.parseInt(s1);
        }
        catch(NumberFormatException numberformatexception)
        {
            num = 0;
        }
        if(num > 0)
        {
            int i = 0;
            String as[] = new String[num];
            i = PkgTools.GetMultiPara(as, s2);
            if(num != i)
                return;
            String as1[] = new String[num];
            i = PkgTools.GetMultiPara(as1, s3);
            if(num != i)
                return;
            String as2[] = new String[num];
            i = PkgTools.GetMultiPara(as2, s4);
            if(num != i)
                return;
            String as3[] = new String[num];
            i = PkgTools.GetMultiPara(as3, s5);
            if(num != i)
                return;
            String as4[] = new String[num];
            i = PkgTools.GetMultiPara(as4, s6);
            if(num != i)
                return;
            vFriend.removeAllElements();
            for(int j = 0; j < num; j++)
            {
                vFriend.addElement(PkgTools.Decodecgi(as1[j]));
                vFriend.addElement(as[j]);
                if(as3[j].equals("0"))
                    vFriend.addElement(MSCMIDlet.multiLang.sMale);
                else
                    vFriend.addElement(MSCMIDlet.multiLang.sFemale);
                vFriend.addElement(as2[j]);
                vFriend.addElement(PkgTools.Decodecgi(as4[j]));
            }

            if(cmdOk == null)
            {
                cmdOk = new Command(MSCMIDlet.multiLang.sAddToFriendList, 1, 2);
                cmdPre = new Command(MSCMIDlet.multiLang.sPre, 1, 2);
                cmdNext = new Command(MSCMIDlet.multiLang.sNext, 1, 1);
                cmdCancel = new Command(MSCMIDlet.multiLang.sCancel, 2, 3);
            }
            GotoUser(0);
            MSCMIDlet.display.setCurrent(form);
        }
    }

    public void receiveHttpResponse(String s)
    {
        String s1;
        String s2;
        s1 = PkgTools.GetParaVal("CMD", s).toUpperCase();
        s2 = PkgTools.GetParaVal("RES", s);
        if(s1.equals("FINGER") && s2.equals("0"))
        {
            synchronized(this)
            {
                vBack.addElement(s);
                if(vBack.size() == 1)
                    doNextResult(s);
            }
            return;
        }
        try
        {
            if(s1.equals("GETINFO") && s2.equals("0"))
            {
                getinforForm = new Form(MSCMIDlet.multiLang.sDetails);
                getinforForm.setCommandListener(this);
                String s3 = PkgTools.GetParaVal("UN", s);
                String s4 = PkgTools.Decodecgi(PkgTools.GetParaVal("NK", s));
                String s5 = PkgTools.GetParaVal("FC", s);
                MSCMIDlet.friendRecord.SetInfor(s3, false, s4, s5);
                if(s3.equals(iUIN))
                {
                    String s6;
                    if(PkgTools.GetParaVal("SX", s).equals("1"))
                        s6 = MSCMIDlet.multiLang.sFemale;
                    else
                        s6 = MSCMIDlet.multiLang.sMale;
                    String s7 = MSCMIDlet.multiLang.GetCombineMsg(28, s4, s3, s6, PkgTools.GetParaVal("AG", s), PkgTools.Decodecgi(PkgTools.GetParaVal("PV", s)));
                    getinforForm.append(s7);
                    if(preWindow == MSCMIDlet.mainForm.GetWindow())
                        cmdBackGetInfor = new Command(MSCMIDlet.multiLang.sCancel, 2, 3);
                    else
                        cmdBackGetInfor = new Command(MSCMIDlet.multiLang.sBack, 2, 3);
                    getinforForm.addCommand(cmdBackGetInfor);
                    iUIN = null;
                    preWindow = MSCMIDlet.instance.getCurrent();
                    MSCMIDlet.display.setCurrent(getinforForm);
                    return;
                }
            }
        }
        catch(NumberFormatException numberformatexception) { }
        catch(Exception exception1) { }
        return;
    }

    public void handleHttpError(String s)
    {
    }

}
